home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / dc-sx107install / sx / developer / assembler / movefile.s next >
Text File  |  1999-11-29  |  9KB  |  495 lines

  1. ;
  2. ; SYSTEM-X MOVEFILES 1.04 By Zed/DC
  3. ;
  4.  
  5.     ;incdir "include:"        ; <-- use this for ASM-One
  6.     include "exec/exec_lib.i"
  7.     include "exec/ports.i"
  8.     include "exec/memory.i"
  9.     include "libraries/dos_lib.i"
  10.     include "dos/dos.i"
  11.  
  12.     STRUCTURE    variables,0
  13.     STRUCT        Node,LN_SIZE
  14.     APTR        ReplyPort
  15.     UWORD        Length
  16.     STRUCT        Str,200
  17.     LONG        Data
  18.     LONG        Command        ; XIMMessage ends here
  19.     STRUCT        filename,34
  20.     STRUCT        filepath,54
  21.     STRUCT        destconfpath,56
  22.     STRUCT        destconfnumstr,10
  23.     STRUCT        inputlistname,72
  24.     LONG        readhandle
  25.     LONG        writehandle
  26.     APTR        filebuf
  27.     LONG        filebufsize
  28.     APTR        DosBase
  29.     APTR        UtilBase
  30.     LABEL        bufsize
  31.  
  32. ExecBase    EQU    $4
  33. _LVOStrnicmp    EQU    -168
  34.  
  35.     SECTION ximdoor,code
  36.  
  37.     clr.b    -1(a0,d0.L)        ; add null to arg
  38.     move.l    a0,d0            ; arg string is the node number
  39.     lea    portmask(PC),a0
  40.     bsr    sprintf
  41.  
  42.     lea    dosname(PC),a1
  43.     moveq    #0,d0            ; version 0
  44.     jsr    _LVOOpenLibrary(A6)
  45.     movea.l    d0,a3            ; store dosbase in a3 (tempo)
  46.  
  47.     move.l    #bufsize,d0
  48.     move.l    #MEMF_CLEAR!MEMF_PUBLIC,d1
  49.     jsr    _LVOAllocMem(a6)
  50.     movea.l    d0,a5
  51.  
  52.     move.l    a3,DosBase(a5)
  53.  
  54.     lea    buffer(PC),a1
  55.     jsr    _LVOFindPort(A6)
  56.     tst.l    d0
  57.     beq    error
  58.     movea.l    d0,a4            ; store *Port in a4
  59.  
  60.     jsr    _LVOCreateMsgPort(A6)
  61.     move.l    d0,ReplyPort(a5)    ; create reply port
  62.  
  63.     move    #bufsize,Length(a5)
  64.     move.l    #1,Command(a5)        ; 1 = Startup
  65.     bsr    putmsg
  66.     clr.b    Str(a5)            ; erase string
  67.  
  68.     lea    fileprompt(PC),a1
  69.     moveq    #32,d1
  70.     bsr    getinput
  71.  
  72.     lea    singlecr(PC),a1
  73.     bsr    print
  74.  
  75.     tst.b    Str(a5)
  76.     beq    exitdoor        ; hit return? exit
  77.  
  78.     lea    Str(a5),a1
  79.     lea    filename(a5),a0
  80.     bsr    strcpy            ; store filename in correct field
  81.  
  82.     bsr    movefile
  83.  
  84. exitdoor
  85.     move.l    #2,Command(a5)        ; 2 = Shutdown
  86.     bsr    putmsg
  87.  
  88.     move.l    ReplyPort(a5),a0
  89.     jsr    _LVODeleteMsgPort(A6)    ; kill reply port
  90.  
  91.     bsr    exit
  92.     moveq    #0,d0
  93.     rts
  94.  
  95. ; ==== MAIN MOVEFILE CODE ====
  96.  
  97. movefile
  98.     sub.l    d4,d4            ; dir number
  99.  
  100.     move.l    #127,Command(a5)    ; 127 = CONFLOCATION
  101.     bsr    putmsg
  102.  
  103.     lea    utilname(PC),a1        ; open utility library
  104.     moveq    #0,d0            ; version 0
  105.     jsr    _LVOOpenLibrary(A6)
  106.     move.l    d0,UtilBase(a5)
  107.     tst.l    d0
  108.     bne    movloop
  109.     rts
  110.  
  111. movloop
  112.     addq    #1,d4
  113.     lea    Str(a5),a0
  114.     move.l    a0,d0            ; conf path
  115.     move.l    d4,d1            ; dir number
  116.     lea    dirmask(PC),a0
  117.     bsr    sprintf
  118.  
  119.     lea    buffer(PC),a1
  120.     lea    inputlistname(a5),a0
  121.     bsr    strcpy
  122.  
  123.     lea    inputlistname(a5),a0
  124.     move.l    a0,d1
  125.     move.l    #MODE_OLDFILE,d2
  126.     move.l    DosBase(a5),a6
  127.     jsr    _LVOOpen(a6)        ; open the list
  128.     tst.l    d0
  129.     beq    endmove
  130.     move.l    d0,readhandle(a5)
  131.  
  132.     move.l    readhandle(a5),d1
  133.     moveq    #0,d2
  134.     move.l    #OFFSET_END,d3
  135.     jsr    _LVOSeek(a6)
  136.     move.l    readhandle(a5),d1
  137.     moveq    #0,d2
  138.     move.l    #OFFSET_BEGINNING,d3
  139.     jsr    _LVOSeek(a6)
  140.     addq.l    #2,d0            ; filesize + 2
  141.     move.l    d0,filebufsize(a5)    ; find filesize
  142.  
  143.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  144.     movea.l    (ExecBase).W,a6
  145.     jsr    _LVOAllocMem(a6)
  146.     tst.l    d0
  147.     move.l    DosBase(a5),a6
  148.     beq    closefile        ; out of memory?
  149.     move.l    d0,filebuf(a5)
  150.     move.l    d0,d5            ; d5 = filebuf
  151.  
  152.     move.l    readhandle(a5),d1
  153.     move.l    d0,d2
  154.     move.l    filebufsize(a5),d3
  155.     jsr    _LVORead(a6)
  156.  
  157. searchloop
  158.     movea.l    d5,a0
  159.     bsr    spacelen        ; count filename length
  160.     movea.l    d5,a0            ; search buffer
  161.     lea    filename(a5),a1        ; filename
  162.     movea.l    UtilBase(a5),a6
  163.     jsr    _LVOStrnicmp(a6)
  164.     tst.l    d0
  165.     beq    showfile
  166.     move.l    DosBase(a5),a6
  167.  
  168. findcr
  169.     addq.l    #1,d5
  170.     movea.l    d5,a0
  171.     cmp.b    #10,(a0)        ; check for CR
  172.     bne    findcr
  173.  
  174. foundcr
  175.     addq.l    #1,d5
  176.     movea.l    d5,a0
  177.     cmp.b    #' ',(a0)        ; check for SPACE
  178.     beq    findcr
  179.     tst.l    (a0)
  180.     bne    searchloop
  181.     bra    freemem
  182.  
  183. showfile
  184.     move.l    #255,d4
  185.     movea.l    d5,a0
  186.     movea.l    d5,a1
  187. showloop
  188.     cmp.b    #10,(a0)+
  189.     bne    showloop
  190.  
  191.     subq.l    #1,a0
  192.     move.b    (a0),d7
  193.     clr.b    (a0)
  194.  
  195.     movem.l    a0-a2,-(sp)
  196.     movea.l    (ExecBase).W,a6
  197.     bsr    print
  198.     move.l    DosBase(a5),a6
  199.     movem.l    (sp)+,a0-a2
  200.  
  201.     move.b    d7,(a0)
  202.  
  203.     movem.l    a0-a2,-(sp)
  204.     lea    singlecr(PC),a1
  205.     movea.l    (ExecBase).W,a6
  206.     bsr    print
  207.     move.l    DosBase(a5),a6
  208.     movem.l    (sp)+,a0-a2
  209.  
  210.     addq.l    #1,a0
  211.     movea.l    a0,a1
  212.  
  213.     cmp.b    #' ',(a0)
  214.     bne    aftershow
  215.  
  216.     tst.l    (a0)
  217.     beq    aftershow
  218.  
  219.     bra    showloop
  220.  
  221. aftershow
  222.     movea.l    a0,a3            ; last char in desc
  223.  
  224.     movea.l    (ExecBase).W,a6
  225.     lea    destconf(PC),a1
  226.     moveq    #9,d1
  227.     bsr    getinput        ; get dest conf number
  228.     lea    Str(a5),a1
  229.     lea    destconfnumstr(a5),a0
  230.     bsr    strcpy
  231.     move.l    #147,Command(a5)    ; BB_PCONFLOCAL = 147
  232.     bsr    putmsg
  233.     tst.b    Str(a5)
  234.     beq    freemem
  235.     lea    Str(a5),a1
  236.     lea    destconfpath(a5),a0
  237.     bsr    strcpy
  238.  
  239.     lea    destarea(PC),a1
  240.     moveq    #10,d1
  241.     bsr    getinput        ; get dest filearea
  242.     lea    singlecr(PC),a1
  243.     bsr    print
  244.     tst.b    Str(a5)
  245.     beq    freemem
  246.     lea    Str(a5),a0
  247.     bsr    atol            ; convert string to number
  248.  
  249.     move.l    d0,d1            ; dir number
  250.     move.l    d0,d7            ; dir number to d7 for future use
  251.     lea    destconfpath(a5),a0
  252.     move.l    a0,d0            ; conf path
  253.     lea    dirmask(PC),a0
  254.     bsr    sprintf
  255.     move.l    DosBase(a5),a6
  256.  
  257.     lea    buffer(PC),a0        ; destination filelist
  258.     move.l    a0,d1
  259.     move.l    #MODE_READWRITE,d2
  260.     jsr    _LVOOpen(a6)
  261.     tst.l    d0
  262.     beq    freemem
  263.     move.l    d0,writehandle(a5)
  264.  
  265.     move.l    d0,d1
  266.     moveq    #0,d2
  267.     move.l    #OFFSET_END,d3
  268.     jsr    _LVOSeek(a6)
  269.  
  270.     move.l    writehandle(a5),d1
  271.     move.l    d5,d2            ; buf
  272.     move.l    a3,a0
  273.     sub.l    d5,a0
  274.     move.l    a0,d3
  275.     jsr    _LVOWrite(a6)
  276.  
  277.     move.l    writehandle(a5),d1
  278.     jsr    _LVOClose(a6)
  279.  
  280.     ; remove from original list    -------
  281.  
  282.     move.l    readhandle(a5),d1
  283.     jsr    _LVOClose(a6)
  284.  
  285.     lea    inputlistname(a5),a0
  286.     move.l    a0,d1
  287.     move.l    #MODE_NEWFILE,d2
  288.     jsr    _LVOOpen(a6)
  289.     move.l    d0,readhandle(a5)
  290.     tst.l    d0
  291.     beq    freemem
  292.  
  293.     move.l    d0,d1            ; d5 = first char, a3 = last char
  294.     move.l    filebuf(a5),d2
  295.     move.l    d5,d3
  296.     sub.l    filebuf(a5),d3
  297.     tst.l    d3
  298.     beq    isfirst            ; removing first file in list
  299.     jsr    _LVOWrite(a6)
  300.  
  301. isfirst
  302.     move.l    a3,d2
  303.     move.l    filebuf(a5),d3
  304.     add.l    filebufsize(a5),d3
  305.     sub.l    d2,d3
  306.     subq.l    #2,d3
  307.     tst.l    d3
  308.     beq    islast            ; removing last file in list
  309.     move.l    readhandle(a5),d1
  310.     jsr    _LVOWrite(a6)
  311.  
  312. islast
  313.     move.l    readhandle(a5),d1
  314.     jsr    _LVOClose(a6)
  315.     clr.l    readhandle(a5)
  316.  
  317.     ;                -------
  318.  
  319.     move.l    (ExecBase).W,a6
  320.     lea    filename(a5),a1
  321.     lea    Str(a5),a0
  322.     bsr    strcpy
  323.     move.l    #1511,Command(a5)    ; SX_FINDFILE
  324.     bsr    putmsg
  325.     tst.b    Str(a5)
  326.     beq    freemem            ; file not found?
  327.     lea    Str(a5),a1
  328.     lea    filepath(a5),a0
  329.     bsr    strcpy
  330.  
  331.     lea    destconfnumstr(a5),a1
  332.     lea    Str(a5),a0
  333.     bsr    strcpy            ; conf number to Msg -> String
  334.     move.l    d7,Data(a5)        ; file area to Msg -> Data
  335.     move.l    #1510,Command(a5)    ; SX_GETPATH (destination path)
  336.     bsr    putmsg
  337.  
  338.     lea    filepath(a5),a0
  339.     move.l    a0,d0
  340.     lea    filename(a5),a0
  341.     move.l    a0,d1
  342.     lea    Str(a5),a0        ; new filepath
  343.     move.l    a0,d2
  344.     lea    movemask(PC),a0
  345.     bsr    sprintf            ; build the move string
  346.  
  347.     lea    buffer(PC),a1
  348.     bsr    print
  349.     lea    doublecr(PC),a1
  350.     bsr    print
  351.  
  352.     lea    buffer(PC),a0
  353.     move.l    a0,d1
  354.     moveq    #0,d2
  355.     moveq    #0,d3
  356.     move.l    DosBase(a5),a6
  357.     jsr    _LVOExecute(a6)        ; move the file to it's new
  358.                     ; home on the harddisk.
  359.  
  360. freemem
  361.     movea.l    filebuf(a5),a1
  362.     move.l    filebufsize(a5),d0
  363.     movea.l    (ExecBase).W,a6
  364.     jsr    _LVOFreeMem(a6)
  365.     move.l    DosBase(a5),a6
  366.  
  367. closefile
  368.     move.l    readhandle(a5),d1
  369.     tst.l    d1
  370.     beq    endmove
  371.     jsr    _LVOClose(a6)
  372.     cmp.l    #255,d4
  373.     bne    movloop
  374.  
  375. endmove
  376.     movea.l    (ExecBase).W,a6
  377.     movea.l    UtilBase(a5),a1
  378.     jsr    _LVOCloseLibrary(A6)
  379.     rts
  380.  
  381. ; ==== END OF MAIN MOVEFILE CODE ====
  382.  
  383. getinput
  384.     lea    Str(a5),a0
  385.     bsr    strcpy
  386.     move.l    #5,Command(a5)
  387.     move.l    d1,Data(a5)
  388.     bsr    putmsg
  389.     rts
  390.  
  391. print
  392.     move.l    #1500,Command(a5)    ;    1500 = print string
  393.     move.l    a1,Data(a5)
  394.  
  395. putmsg
  396.     move.l    a4,a0
  397.     move.l    a5,a1
  398.     jsr    _LVOPutMsg(A6)
  399.  
  400.     move.l    ReplyPort(a5),a0
  401.     jsr    _LVOWaitPort(A6)
  402.  
  403.     move.l    ReplyPort(a5),a0
  404.     jsr    _LVOGetMsg(A6)
  405.     rts
  406.  
  407. error
  408.     move.l    DosBase(a5),a6
  409.     lea    errormsg(PC),a1
  410.     move.l    a1,d1
  411.     jsr    _LVOPutStr(A6)
  412.     movea.l    (ExecBase).W,a6
  413.  
  414. exit
  415.     move.l    DosBase(a5),a1
  416.     jsr    _LVOCloseLibrary(A6)
  417.  
  418.     movea.l    a5,a1
  419.     move.l    #bufsize,d0
  420.     jsr    _LVOFreeMem(a6)
  421.     rts
  422.  
  423. sprintf
  424.     movem.l    D0-D3/A0-A3,-(SP)
  425.     move.l    SP,A1
  426.     lea    PutChar(PC),A2
  427.     lea    buffer(PC),A3
  428.     movea.l    (ExecBase).W,A6
  429.     jsr    _LVORawDoFmt(A6)
  430.     movem.l    (SP)+,D0-D3/A0-A3
  431.     rts
  432.  
  433. PutChar
  434.     move.b    d0,(a3)+
  435.     rts
  436.  
  437. ;strlen
  438. ;    MOVEA.L    A0,A1
  439. ;slloop
  440. ;    tst.b    (A1)+
  441. ;    bne.s    slloop
  442. ;    SUBQ.L    #1,A1
  443. ;    SUBA.L    A0,A1
  444. ;    move.l    a1,d0
  445. ;    rts
  446.  
  447. spacelen
  448.     movea.l    a0,a1
  449. sploop
  450.     cmp.b    #' ',(a1)+        ; counts char's before the space
  451.     bne.s    sploop
  452.     subq.l    #1,a1
  453.     suba.l    a0,a1
  454.     move.l    a1,d0
  455.     rts
  456.  
  457. strcpy
  458.     move.b    (a1)+,(a0)+        ; copy a1 to a0
  459.     bne.s    strcpy
  460.     rts
  461.  
  462. atol    moveq    #0,d0            ; convert ascii to decimal
  463.     moveq    #0,d1
  464. nextn    move.b    (a0)+,d1
  465.     tst.b    d1
  466.     beq    finn
  467.     cmp.b    #"0",d1
  468.     bmi    nextn
  469.     cmp.b    #"9",d1
  470.     bhi    nextn
  471.     sub.b    #"0",d1
  472.     move.l    d0,d2
  473.     asl.l    #3,d0
  474.     add.l    d2,d0
  475.     add.l    d2,d0
  476.     add.l    d1,d0
  477.     bra    nextn
  478. finn    rts
  479.  
  480.  
  481. buffer:        dc.b    0,"FLID","$VER: System-X_MoveFiles 1.04 (06-Aug-97)",0
  482. dosname:    dc.b    "dos.library",0
  483. utilname:    dc.b    "utility.library",0
  484. portmask:    dc.b    "AEDoorPort%s",0
  485. errormsg:    dc.b    "This must be run from System-X BBS.",10,0
  486. dirmask:    dc.b    "%sDir%ld",0
  487. movemask:    dc.b    "Move %s%s %s",0
  488. fileprompt:    dc.b    27,"[0;36m",13,10,13,10,"Enter filename to move: ",27,"[0m",0
  489. destconf:    dc.b    13,10,27,"[0;36mDestination Conference (CR = Cancel): ",27,"[0m",0
  490. destarea:    dc.b    13,10,27,"[0;36mDestination File Area  (CR = Cancel): ",27,"[0m",0
  491. singlecr:    dc.b    13,10,0
  492. doublecr:    dc.b    13,10,13,10,0
  493.         even
  494.         end
  495.